<?php
/**
 * [WeEngine System] Copyright (c) 2014 WE7.CC
 * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
 */
defined('IN_IA') or exit('Access Denied');
define('IN_GW', true);
if(checksubmit() || $_W['isajax']) {
	_login($_GPC['referer']);
}
$setting = $_W['setting'];
template('user/login');
// echo 000;die;
function _login($forward = '') {
	global $_GPC, $_W;
	load()->model('user');
	$member = array();
	$username = trim($_GPC['username']);

	if(empty($username)) {
		message('请输入要登录的账号');
	}
	$member['username'] = $username;
	$member['password'] = $_GPC['password'];
	if(empty($member['password'])) {
		message('请输入密码');
	}
    $res=pdo_get('zh_yjm_store',array('admin'=>$username));
    if ($res['state']!=1) {
    	message('被禁用,请联系管理员');
    }
	$record = user_single($member);//似乎是检查用户名和密码
	if(!empty($record)) {
	    $cookie = array();
		$cookie['uid'] = $record['uid'];
		$cookie['lastvisit'] = $record['lastvisit'];
		$cookie['lastip'] = $record['lastip'];
		$cookie['hash'] = md5($record['password'] . $record['salt']);
		$session = base64_encode(json_encode($cookie));
		isetcookie('__session', $session, !empty($_GPC['rember']) ? 7 * 86400 : 0, true);
		message("欢迎回来，{$record['username']}！", url('site/entry/cussell', array('m' => 'zh_yjm'), 'success'));
		    
		    //https://hl.zhycms.com//web/index.php?c=site&a=entry&op=display&do=goodscate&m=zh_yjm
		    // message("欢迎回来，{$res[0]['name']}！", url('site/entry/goodscate', array('m' => 'zh_yjm', 'id' => $storeid, 'do' => 'goodscate')), 'success');
	} else {
		message('登录失败，请检查您输入的用户名和密码！');
	}
}